from sqlalchemy import Column, Integer, String, ForeignKey, ARRAY
from sqlalchemy.orm import relationship

from .base import BaseModel
from .course import Course
from .user import User


class Chapter(BaseModel):
    # @RISK 如果课程的的目录层级非常多，章节下还分小结怎么兼容？
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(512), nullable=False, unique=False, comment="章节名称")
    # o_path = Column(String(512), nullable=False, unique=True,
    #                 comment="vs库生成的Chapter对象的存放目录")
    output_dir = Column(String(512), comment="处理后的输出存储目录，释放资源可用到")
    img = Column(String(512), nullable=True)
    user_id = Column(Integer, ForeignKey(User.id),
                     nullable=False, comment='创建该章节的用户')
    course_id = Column(Integer, ForeignKey(Course.id),
                       nullable=True, comment='章节属于的课程')
    videos = relationship('Video', backref='chapter', lazy=True)
